<?php

namespace WoXuanWang\Video\Models;

use Eloquent as Model;
use WoXuanWang\Video\Models\VideoCategory;

/**
 * Class VideoCategory
 * @package WoXuanWang\VideoCategory\Models
 * @version April 6, 2017, 2:03 pm CST
 */
class VideoCategory extends Model
{

	public $table = 'video_categories';


	public $fillable = [
		'name',
		'created_by',
		'parent_id'
	];

	/**
	 * The attributes that should be casted to native types.
	 *
	 * @var array
	 */
	protected $casts = [
		'name'       => 'string',
		'created_by' => 'integer',
		'parent_id'  => 'integer'
	];

	/**
	 * Validation rules
	 *
	 * @var array
	 */
	public static $rules = [
		'name' => 'required'
	];

	/**
	 * @return \Illuminate\Database\Eloquent\Relations\HasOne
	 **/
	public function user()
	{
		return $this->hasOne(\WoXuanWang\User\Models\User::class, 'created_by', 'id');
	}

	public function parent()
	{
		return $this->belongsTo(VideoCategory::class, 'parent_id', 'id');
	}

	public function subVideoCategories()
	{
		return $this->hasMany(VideoCategory::class, 'parent_id', 'id');
	}

}
